package com.luguokong.pet_rescue.controller;

import com.luguokong.pet_rescue.pojo.Comment;
import com.luguokong.pet_rescue.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentCtrl {

    @Autowired
    private CommentService commentService;

    @GetMapping("/getByPage")
    public List<Comment> selectCommentAllByPageNumByPageSize(int pageNum, int pageSize){
        System.out.println("1111111111111111111");
        List<Comment> commentList = commentService.selectCommentAllByPageNumByPageSize((pageNum-1) * pageSize, pageSize);
        return commentList;
    }

    @GetMapping("/getDataCount")
    public int selectDataCount(){
        int i = commentService.selectDataCount();
        return i;
    }

    @PostMapping("/insertComment")
    public int insertComment(@RequestBody Comment comment){
        int i = commentService.insertComment(comment);
        return i;
    }

    @GetMapping("/deleteCommentById")
    public int deleteCommentById(int cmtId){
        int i = commentService.deleteCommentById(cmtId);
        return i;
    }

    @PostMapping("/deleteCommentByArrId")
    public int deleteCommentByCmtIdArray(@RequestBody int [] cmtIdArr){
        int i = commentService.deleteCommentByCmtIdArray(cmtIdArr);
        return i;
    }
}
